﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EmailingWeeklyProgressReportSettings : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
		{
			string message;
			var dt = new DataLayer().GetEmailDeliverySettings(PAConfiguration.ConnectionString, out message);

			if (dt.Rows.Count > 0)
			{
				DateTime nextDeliveryDate = (DateTime) dt.Rows[0]["NEXT_DELIV_DATE"];
				radDP_DeliveryDate.SelectedDate = nextDeliveryDate;
				txtDeliveryHour.Text = nextDeliveryDate.Hour.ToString();
				txtDeliveryMinutes.Text = nextDeliveryDate.Minute.ToString();

				ddlFrequency.SelectedValue = dt.Rows[0]["FREQUENCY"].ToString();
			}
		}
    }
	protected void btnSave_Click(object sender, EventArgs e)
	{
		DateTime date = radDP_DeliveryDate.SelectedDate == null
		                	? DateTime.Now
		                	: new DateTime(radDP_DeliveryDate.SelectedDate.Value.Year,
		                	               radDP_DeliveryDate.SelectedDate.Value.Month,
		                	               radDP_DeliveryDate.SelectedDate.Value.Day,
		                	               Convert.ToInt32(txtDeliveryHour.Text),
		                	               Convert.ToInt32(txtDeliveryMinutes.Text), 0);
		decimal frequency = Convert.ToDecimal(ddlFrequency.SelectedValue);
		string message;
		new DataLayer().SaveEmailDeliverySettings(PAConfiguration.ConnectionString, date, frequency, out message);
	}
	protected void btnCancel_Click(object sender, EventArgs e)
	{

	}
}